import request from '@/utils/request'

// 定向包
export function getFixPackgeList (data) {
  const params = {
    filtering: [],
    order_by: data.order_by,
    order_type: data.order_type,
    page: data.page,
    page_size: data.page_size
  }
  if (data.keyWord) {
    if( parseInt(data.keyWord) == data.keyWord){
      params.filtering.push({
        field: 'id',
        operator: 'LIKE',
        value: data.keyWord
      })
    }else {
      params.filtering.push({
        field: 'name',
        operator: 'LIKE',
        value: data.keyWord
      })
    }
  }
  if (data.delivery_range) {
    params.filtering.push({
      field: 'delivery_range',
      operator: 'EQUALS',
      value: data.delivery_range
    })
  }
  if (data.landing_type) {
    params.filtering.push({
      field: 'landing_type',
      operator: 'EQUALS',
      value: data.landing_type
    })
  }
  if (data.account_id) {
    params.filtering.push({
      field: 'account_id',
      operator: 'EQUALS',
      value: data.account_id
    })
  }
  if (data.created_at && data.created_at.length > 0) {
    params.filtering.push({
      field: 'created_at',
      operator: 'GREATER_EQUALS',
      value: data.created_at[0]
    })
    params.filtering.push({
      field: 'created_at',
      operator: 'LESS_EQUALS',
      value: data.created_at[1]
    })
  }
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + '/admin/ocean/audience_templete/select',
    method:'post',
    data: params
  })
}

// 定向包新增
export function fixPackgeAdd (audience,estimate) {
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + '/admin/ocean/audience_templete/create',
    method:'post',
    data: {audience:audience,estimate:estimate}
  })
}

// 定向包编辑
export function fixPackgeEdit (data) {
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + '/admin/ocean/audience_templete/update',
    method:'post',
    data: data
  })
}

// 定向包详情
export function fixPackgeDetails (id) {
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + '/admin/ocean/audience_templete/read',
    method:'post',
    data: {id:id}
  })
}

// 定向包删除
export function fixPackgeDelete (id) {
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + `/admin/ocean/audience_templete/delete`,
    method:'post',
    data: {id:id}
  })
}

